/**
 * 
 */
package com.goodedeeds.webapp.controller;

import com.goodedeeds.webapp.LoginHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.validation.SimpleError;

/**
 * @author ravi
 *
 */
@UrlBinding(LoginAction.URL)
public class LoginAction extends RegisterAction {

	public static final String URL = "/login.action";

    private String loginEmail;
    private String loginPassword;

    public Resolution login(){
		boolean login = LoginHandler.getInstance().doLogin(getLoginEmail(), getLoginPassword(), getContext().getRequest(), getContext().getResponse());

        if(login){
			return new RedirectResolution(HomeAction.URL);
		}else{
            addValidationError("loginEmail",  new SimpleError("Invalid email/password"));
        }
		
		return showPage();
	}
	
	public Resolution logout(){
		LoginHandler.getInstance().doLogout(getContext().getRequest(), getContext().getResponse());
		return showPage();
	}

    public String getLoginEmail() {
        return loginEmail;
    }

    public void setLoginEmail(String loginEmail) {
        this.loginEmail = loginEmail;
    }

    public String getLoginPassword() {
        return loginPassword;
    }

    public void setLoginPassword(String loginPassword) {
        this.loginPassword = loginPassword;
    }
}
